﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using DBA.Data;
using DBA.Data.Hibernate;
using DBA.Model;

namespace Demo
{
    public partial class demo_page2Add : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) return;
        }
        NHibernateQuery dal = CommonQuery.NHibernateQuery;


        protected void lbtn_Save_Click(object sender, EventArgs e)
        {
            Test_UserInfo userInfo = new Test_UserInfo();
            userInfo.UserName = txtUserName.Text.Trim();
            userInfo.Address = txtAddress.Text.Trim();
            userInfo.IDcard = txtIDCard.Text.Trim();
            userInfo.Phone = txtPhone.Text.Trim();
            userInfo.Mobile = txtMobile.Text.Trim();
            userInfo.Email = txtEmail.Text.Trim();
            userInfo.PostalCode = txtPostalCode.Text.Trim();

            int reValue = dal.Insert<Test_UserInfo>(userInfo);

            if (reValue > 0)
            {
                ScriptManager.RegisterStartupScript(this, base.GetType(), "insertOk" + System.Guid.NewGuid().ToString(), "Public.OpertAlert('数据添加成功',true);", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, base.GetType(), "insertError" + System.Guid.NewGuid().ToString(), "alert('数据添加失败!');", true);
            }

            //dal.ManagerParameter.ClearParameter();
            //dal.ManagerParameter.AddNewInParameter("UserName", txtUserName.Text.Trim());
            //dal.ManagerParameter.AddNewInParameter("Address", txtAddress.Text.Trim());
            //dal.ManagerParameter.AddNewInParameter("IDcard", txtIDCard.Text.Trim());
            //dal.ManagerParameter.AddNewInParameter("Phone", txtPhone.Text.Trim());
            //dal.ManagerParameter.AddNewInParameter("Mobile", txtMobile.Text.Trim());
            //dal.ManagerParameter.AddNewInParameter("Email", txtEmail.Text.Trim());
            //dal.ManagerParameter.AddNewInParameter("PostalCode", txtPostalCode.Text.Trim());
            //dal.ModifyData.Insert("test_UserInfo");
            //string sql = "insert into test_UserInfo(UserName,Address,IDcard,Phone,Mobile,Email,PostalCode) values "
            //           + "('" + txtUserName.Text.Trim() + "','" + txtAddress.Text.Trim() + "',"
            //           + "'" + txtIDCard.Text.Trim() + "','" + txtPhone.Text.Trim() + "',"
            //           + "'" + txtMobile.Text.Trim() + "','" + txtEmail.Text.Trim() + "',"
            //           + "'" + txtPostalCode.Text.Trim() + "')";
            //dal.ExecuteNonQuery(sql);
            //if (String.IsNullOrEmpty(dal.ErrorMessage))
            //{
            //    ScriptManager.RegisterStartupScript(this, base.GetType(), "insertOk" + System.Guid.NewGuid().ToString(), "Public.OpertAlert('数据添加成功',true);", true);
            //}
            //else
            //{
            //}
        }
    }
}